#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# Copyright (C) 2009, Aşkın Yollu <askin@askin.ws>
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free
# Software Foundation; either version 2 of the License, or (at your option)
# any later version.
#
# Please read the COPYING file.
#


import sys, signal
from PyQt4 import QtGui, QtCore
from mainwindow import MainWindow
from ConvertImage import ConvertImage

def main(command_line):
    signal.signal(signal.SIGINT, signal.SIG_DFL)
    app = QtGui.QApplication(sys.argv)

    app.setApplicationName("resize")
    app.setOrganizationName("resize")

    locale = QtCore.QLocale.system().name()
    print("locale: %s" % locale)
    translator = QtCore.QTranslator()
    translator.load(":/kde4_rotate_%s.qm" % locale)
    app.installTranslator(translator)

    mainWindow = MainWindow()
    mainWindow.setWindowTitle("Resize Image")

    mainWindow.bgSize = QtGui.QButtonGroup()
    mainWindow.bgName = QtGui.QButtonGroup()
    mainWindow.bgName.addButton(mainWindow.rbAppend)
    mainWindow.bgName.addButton(mainWindow.rbResizeInPlace)
    mainWindow.bgSize.addButton(mainWindow.rbCustomSize)
    mainWindow.bgSize.addButton(mainWindow.rbScale)
    mainWindow.bgSize.addButton(mainWindow.rbSelectSize)
    mainWindow.rbSelectSize.animateClick()

    print mainWindow.images
    for img in command_line:
        try:
            mainWindow.images.append(ConvertImage(img))
        except Exception, e:
            print e
            pass

    print len(mainWindow.images)
    if len(mainWindow.images) == 0:
        mainWindow.quit()
    else:
        mainWindow.show()
        return app.exec_()

if __name__ == "__main__":
    main()
